package com.lw.chat.view.chat;

import com.lw.chat.model.Message;
import de.saxsys.mvvmfx.ViewModel;
import de.saxsys.mvvmfx.utils.mapping.ModelWrapper;
import javafx.beans.property.BooleanProperty;
import javafx.beans.property.StringProperty;

public class MessageBoxViewMeModel implements ViewModel {


    private ModelWrapper<Message> wrapper = new ModelWrapper<>();

    public MessageBoxViewMeModel() {

    }


    public void setMessage(Message messageModel) {
        wrapper.set(messageModel);
        wrapper.reload();
        publish("msgStyle", messageModel.getOtherSide());
    }

    public StringProperty userNameProperty(){
        return wrapper.field("userName", Message::getUserName, Message::setUserName, "");
    }

    public StringProperty avatarUriProperty(){
        return wrapper.field("avatarUri", Message::getAvatarUri, Message::setAvatarUri, "");
    }

    public StringProperty msgImageUriProperty(){
        return wrapper.field("msgImageUri", Message::getMsgImageUri, Message::setMsgImageUri, "");
    }
    public StringProperty messageProperty(){
        return wrapper.field("message", Message::getMessage, Message::setMessage, "");
    }

    public BooleanProperty otherSideProperty() {
        return wrapper.field("otherSide", Message::getOtherSide, Message::setOtherSide, true);
    }
}
